package com.xinchuang.util;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xinchuang.entity.target.TargetBaseData;
import com.xinchuang.entity.targetSystem.target.IndexRelationTable;
import org.apache.commons.lang3.StringUtils;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.Polygon;
import org.osgeo.proj4j.*;

import java.awt.*;
import java.awt.geom.Point2D;
import java.math.BigDecimal;
import java.util.*;
import java.util.List;

/**
 * TODO
 *
 * @author zkwczx
 * @version 1.0
 * @date 2021/11/26 14:51
 */
public class LngLatUtil {

    static double M_PI = Math.PI;

    /**
     * 位置实体类，根据自己的来即可
     */
    public static class Position {

        /**
         * 纬度
         */
        private Double latitude;

        /**
         * 经度
         */
        private Double longitude;

        public Double getLatitude() {
            return latitude;
        }

        public void setLatitude(Double latitude) {
            this.latitude = latitude;
        }

        public Double getLongitude() {
            return longitude;
        }

        public void setLongitude(Double longitude) {
            this.longitude = longitude;
        }

        public Position(Double latitude, Double longitude) {
            this.latitude = latitude;
            this.longitude = longitude;
        }
    }

    public static JSONArray getPosition(String plotinfoobj) {
        JSONArray array = new JSONArray();
        if (StringUtils.isBlank(plotinfoobj)) {
            return array;
        }
        JSONObject object = JSONObject.parseObject(plotinfoobj);
        JSONArray positions = object.getJSONArray("positions");
        LinkedList<Position> postionList = new LinkedList<>();
        for (int i = 0; i < positions.size(); i++) {
            JSONArray jsonArray = positions.getJSONArray(i);
            postionList.add(new Position(jsonArray.getDouble(1), jsonArray.getDouble(0)));
        }
        Map<String, Double> point = getCenterPoint(postionList);
        Double centerLon = point.get("centerLon");
        Double centerLat = point.get("centerLat");
        System.out.println(point.get("centerLon"));
        System.out.println(point.get("centerLat"));
        array.add(rad(centerLon));
        array.add(rad(centerLat));
        array.add(0D);
        return array;
    }

    public static void main(String[] args) {
        Position position1 = new Position(18.543133052773655, 111.12305721011614);
        Position position2 = new Position(9.785408654552441, 120.5627054646734);
        LinkedList<Position> postionList = new LinkedList<>();
        postionList.add(position1);
        postionList.add(position2);
        Map<String, Double> point = getCenterPoint(postionList);
        System.out.println(point.get("centerLon") + "," + point.get("centerLat"));
    }

    /**
     * 取几个经纬度的中心点
     *
     * @param postionList 经纬度的集合
     */
    public static Map<String, Double> getCenterPoint(LinkedList<Position> postionList) {
        int total = postionList.size();
        double X = 0, Y = 0, Z = 0;
        while (!postionList.isEmpty()) {
            Position g = postionList.pollFirst();
            if (g != null) {
                double lat, lon, x, y, z;
                lat = g.getLatitude() * Math.PI / 180;
                lon = g.getLongitude() * Math.PI / 180;
                x = Math.cos(lat) * Math.cos(lon);
                y = Math.cos(lat) * Math.sin(lon);
                z = Math.sin(lat);
                X += x;
                Y += y;
                Z += z;
            }
        }
        X = X / total;
        Y = Y / total;
        Z = Z / total;
        double Lon = Math.atan2(Y, X);
        double Hyp = Math.sqrt(X * X + Y * Y);
        double Lat = Math.atan2(Z, Hyp);
        double longitude = Lon * 180 / Math.PI;
        double latitude = Lat * 180 / Math.PI;
        HashMap<String, Double> map = new HashMap<>();
        map.put("centerLon", longitude);
        map.put("centerLat", latitude);
        return map;
    }

    //地球半径
    private static double EARTH_RADIUS = 6378.137;

    //弧度转化
    public static double rad(double d) {
        return d * Math.PI / 180.0;
    }

    /**
     * 通过经纬度获取距离(单位：千米)
     *
     * @param lat1
     * @param lng1
     * @param lat2
     * @param lng2
     * @return
     */
    public static double getDistance(double lng1, double lat1, double lng2, double lat2) {
        double patm = 2;
        double radLat1 = rad(lat1);
        double radLat2 = rad(lat2);
        double difference = radLat1 - radLat2;
        double mdifference = rad(lng1) - rad(lng2);
        double distance = patm * Math.asin(Math.sqrt(Math.pow(Math.sin(difference / patm), patm)
                + Math.cos(radLat1) * Math.cos(radLat2)
                * Math.pow(Math.sin(mdifference / patm), patm)));
        distance = distance * EARTH_RADIUS;
        return distance;
    }

    /**
     * 获取瓦片的中心点数据
     *
     * @param minLat
     * @param minLon
     * @param maxLat
     * @param maxLon
     * @return
     */
    public static Map<String, Double> toTileKeyCenter(Double minLat, Double minLon, Double maxLat, Double maxLon, boolean change) {
        if (change) {
            double[] doubleMin = Mercator2lonLat(minLon, minLat);
            minLon = doubleMin[0];
            minLat = doubleMin[1];
            double[] doubleMax = Mercator2lonLat(maxLon, maxLat);
            maxLon = doubleMax[0];
            maxLat = doubleMax[1];
        }
        LinkedList<Position> list = new LinkedList<>();
        list.add(new Position(maxLat, minLon));
        list.add(new Position(maxLat, maxLon));
        list.add(new Position(minLat, maxLon));
        list.add(new Position(minLat, minLon));
        Map<String, Double> map = getCenterPoint(list);
        LinkedList<Position> listOn = new LinkedList<>();
        listOn.add(new Position(maxLat, minLon));
        listOn.add(new Position(maxLat, maxLon));
        Map<String, Double> mapOn = getCenterPoint(listOn);
        double radius = getDistance(map.get("centerLat"), map.get("centerLon"), mapOn.get("centerLat"), mapOn.get("centerLon"));
        map.put("minLat", minLat);
        map.put("minLon", minLon);
        map.put("maxLat", maxLat);
        map.put("maxLon", maxLon);
        map.put("radius", radius);
        return map;
    }

    public static double[] Mercator2lonLat(double mercatorX, double mercatorY) {
        double[] xy = new double[2];
        double x = mercatorX / 20037508.34 * 180;
        double y = mercatorY / 20037508.34 * 180;
        y = 180 / M_PI * (2 * Math.atan(Math.exp(y * M_PI / 180)) - M_PI / 2);
        xy[0] = x;
        xy[1] = y;
        return xy;
    }

    /**
     * 将经纬度转换为度分秒格式
     *
     * @param du 116.418847
     * @return 116°25'7.85"
     */
    public static String changeToDFM(double du) {
        int du1 = (int) du;
        double tp = (du - du1) * 60;
        int fen = (int) tp;
        String miao = String.format("%.2f", Math.abs(((tp - fen) * 60)));
        return du1 + "°" + Math.abs(fen) + "'" + miao + "\"";
    }

    /**
     * 度分秒转经纬度
     *
     * @param dms 116°25'7.85"
     * @return 116.418847
     */
    public static double changeToDu(String dms) {
        if (dms == null) {
            return 0;
        }
        try {
            dms = dms.replace(" ", "");
            String[] str2 = dms.split("°");
            if (str2.length < 2) {
                return 0;
            }
            int d = Integer.parseInt(str2[0]);
            String[] str3 = str2[1].split("\'");
            if (str3.length < 2) {
                return 0;
            }
            int f = Integer.parseInt(str3[0]);
            String str4 = str3[1].substring(0, str3[1].length() - 1);
            double m = Double.parseDouble(str4);
            double fen = f + (m / 60);
            double du = (fen / 60) + Math.abs(d);
            if (d < 0) {
                du = -du;
            }
            return du;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    /**
     * 将经纬度转换为度分秒格式
     *
     * @param du 116.418847        40.0897315
     * @return 116°25'7.85"       40°5'23.03"
     */
    public static String latLng2Dfm(double du) {
        int du1 = (int) du;
        double tp = (du - du1) * 60;
        int fen = (int) tp;
        String miao = String.format("%.1f", Math.abs(((tp - fen) * 60)));
        if (miao.contains(".") && miao.split("\\.")[0].length() == 1) {
            return du1 + "°" + Math.abs(fen) + "'0" + miao + "\"";
        }
        return du1 + "°" + Math.abs(fen) + "'" + miao + "\"";
    }

    public static List<Double> formatLngLat(String position) {
        if (StringUtils.isNotEmpty(position)) {
            if (position.contains(",")) {
                String[] split = position.split(",");
                return Arrays.asList(changeToDu(split[0]), changeToDu(split[1]), 0.0);
            }
        }
        return Arrays.asList(0.09887316937991386, 0.08726753962206146, 0.0);
    }

    /**
     * 将经纬度转换为度分秒格式
     *
     * @param du 116.418847        40.0897315
     * @return 116°25'7.85"       40°5'23.03"
     */
    public static String latLng2DfmStr(double du) {
        int du1 = (int) du;
        double tp = (du - du1) * 60;
        int fen = (int) tp;
        String miao = String.format("%.2f", Math.abs(((tp - fen) * 60)));
        return du1 + "度" + Math.abs(fen) + "分" + miao + "秒";
    }

    /**
     * 度分秒转经纬度
     *
     * @param dms 116°25'7.85"
     * @return 116.418847
     */
    public static double dfm2LatLng(String dms) {
        if (dms == null) {
            return 0;
        }
        try {
            dms = dms.replace(" ", "");
            String[] str2 = dms.split("°");
            if (str2.length < 2) {
                return 0;
            }
            int d = Integer.parseInt(str2[0]);
            String[] str3 = str2[1].split("\'");
            if (str3.length < 2) {
                return 0;
            }
            int f = Integer.parseInt(str3[0]);
            String str4 = str3[1].substring(0, str3[1].length() - 1);
            double m = Double.parseDouble(str4);

            double fen = f + (m / 60);
            double du = (fen / 60) + Math.abs(d);
            if (d < 0) {
                du = -du;
            }
            return Double.parseDouble(String.format("%.7f", du));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    /**
     * 度分秒转经纬度
     *
     * @param dms 116°25'7.85"
     * @return 116.418847
     */
    public static double dfm2LatLng(String dms, String duStr, String fenStr) {
        if (StringUtils.isBlank(dms)) {
            return 0;
        }
        try {
            dms = dms.replace(" ", "");
            String[] str2 = dms.split(duStr);
            if (str2.length < 2) {
                return 0;
            }
            int d = Integer.parseInt(str2[0]);
            String[] str3 = str2[1].split(fenStr);
            if (str3.length < 2) {
                return 0;
            }
            int f = Integer.parseInt(str3[0]);
            String str4 = str3[1].substring(0, str3[1].length() - 1);
            double m = Double.parseDouble(str4);

            double fen = f + (m / 60);
            double du = (fen / 60) + Math.abs(d);
            if (d < 0) {
                du = -du;
            }
            return Double.parseDouble(String.format("%.7f", du));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    /**
     * 将经纬度转换为度分格式
     *
     * @param du 116.418847      40.0897315
     * @return 116°25'          40°5'
     */
    private static Object latLng2Df(double du) {
        int du1 = (int) du;
        double tp = (du - du1) * 60;
        int fen = (int) tp;
        return du1 + "°" + Math.abs(fen) + "'";
    }

    /**
     * 度分转经纬度
     * 全球经纬度的取值范围为：纬度-90~90，经度-180~180
     * 度分转换： 将度分单位数据转换为度单位数据，公式：度=度+分/60
     * 例如： 经度 = 116°20.12'，纬度 = 39°12.34'
     * 经度 = 116 + 20.12 / 60 = 116.33533°
     * 纬度 = 39 + 12.34 / 60 = 39.20567°
     *
     * @param dm 4005.38389 ddmm.mmmmm
     * @return 40.0897315
     * 11616.02846 dddmm.mmmmm
     * 116.267141
     */
    public static double df2LatLng(String dm) {
        if (dm == null) {
            return 0;
        }
        try {
            dm = dm.replace(" ", "");
            int d = parseInteger(dm.substring(0, dm.lastIndexOf(".") - 2));
            double fen = Double.parseDouble(dm.substring(2));

            double lat = (fen / 60) + Math.abs(d);
            if (lat < 0) {
                lat = -lat;
            }
            return Double.parseDouble(String.format("%.7f", lat));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static Integer parseInteger(String str) {
        if (str == null || str.isEmpty()) {
            return 0;
        }
        return Integer.valueOf(str);
    }

    /**
     * @return java.lang.String
     * @author zhangxuan
     * @Description TODO 判断当前方位
     * @Date 17:44 2022/5/12
     * @Param [lng1, lat1, lng2, lat2]
     **/
    public static String getOrientation(Double lng1, Double lat1, Double lng2, Double lat2) {
        if (null == lng1 || null == lat1 || null == lng2 || null == lat2) {
            return "";
        }
        StringBuffer sb = new StringBuffer("");
        if (lng1 > lng2) {
            sb.append("东");
        } else if (lng1 < lng2) {
            sb.append("西");
        }
        if (lat1 > lat2) {
            sb.append("南");
        } else if (lat1 < lat2) {
            sb.append("北");
        }
        return StringUtils.isBlank(sb.toString()) ? "中部" : sb.toString() + "部";
    }

    /**
     * 判断一个坐标是否在一个多边形的范围内
     * @param point
     * @param polygon
     * @return
     */
    public static boolean areaCheck(Point2D.Double point, List<Point2D.Double> polygon) {
        java.awt.geom.GeneralPath generalPath = new java.awt.geom.GeneralPath();
        Point2D.Double first = polygon.get(0);
        // 通过移动到指定坐标（以双精度指定），将一个点添加到路径中
        generalPath.moveTo(first.x, first.y);
        polygon.remove(0);
        for (Point2D.Double d : polygon) {
            // 通过绘制一条从当前坐标到新指定坐标（以双精度指定）的直线，将一个点添加到路径中。
            generalPath.lineTo(d.x, d.y);
        }
        // 将几何多边形封闭
        generalPath.lineTo(first.x, first.y);
        generalPath.closePath();
        // 测试指定的 Point2D 是否在 Shape 的边界内。
        return generalPath.contains(point);
    }

    public static double getArea(String plotinfoobj) {
        if (StringUtils.isBlank(plotinfoobj)) {
            return 0;
        }
        try {
            JSONObject json = JSONObject.parseObject(plotinfoobj);
            if (CollectionUtil.isNotEmpty(json.getJSONArray("positions"))) {
                JSONArray positions = json.getJSONArray("positions");
                Coordinate[] coordinates = new Coordinate[positions.size() + 1];
                double lon = 0;
                double lat = 0;
                for (int i = 0; i < positions.size(); i++) {
                    JSONArray array = positions.getJSONArray(i);
                    if (i == 0) {
                        lon = FileElseUtil.getObjectToDouble(array.get(0));
                        lat = FileElseUtil.getObjectToDouble(array.get(1));
                    }
                    coordinates[i] = new Coordinate(FileElseUtil.getObjectToDouble(array.get(0)), FileElseUtil.getObjectToDouble(array.get(1)));
                }
                coordinates[positions.size()] = new Coordinate(lon, lat);
                return area(coordinates);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static double area(Coordinate[] coordinates) {
        GeometryFactory geometryFactory = new GeometryFactory();
        Polygon polygon = geometryFactory.createPolygon(coordinates);
        double area = polygon.getArea();
        return area;
    }

    /**
     * WGS84->2000国家大地坐标系(CGCS2000)
     *
     * @param longitude WGS84经度值
     * @param latitude WGS84纬度值
     * @return x,y CGCS2000经度值,CGCS2000纬度值
     */
    public static Map<String, Double> WGS84ToCGCS2000(double longitude, double latitude) {
        CRSFactory crsFactory = new CRSFactory();
        CoordinateReferenceSystem WGS84 = crsFactory.createFromName("epsg:4326");
        // 根据经度范围确定转换标准,具体EPSG定义参考https://epsg.io
        String degree3EPSG = "epsg:4528";
        if (longitude < 76.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 25
            degree3EPSG = "epsg:4513";
        } else if (longitude >= 76.3 && longitude < 79.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 26
            degree3EPSG = "epsg:4514";
        } else if (longitude >= 79.3 && longitude < 82.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 27
            degree3EPSG = "epsg:4515";
        } else if (longitude >= 82.3 && longitude < 85.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 28
            degree3EPSG = "epsg:4516";
        } else if (longitude >= 85.3 && longitude < 88.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 29
            degree3EPSG = "epsg:4517";
        } else if (longitude >= 88.3 && longitude < 91.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 30
            degree3EPSG = "epsg:4518";
        } else if (longitude >= 91.3 && longitude < 94.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 31
            degree3EPSG = "epsg:4519";
        } else if (longitude >= 94.3 && longitude < 97.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 32
            degree3EPSG = "epsg:4520";
        } else if (longitude >= 97.3 && longitude < 100.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 33
            degree3EPSG = "epsg:4521";
        } else if (longitude >= 100.3 && longitude < 103.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 34
            degree3EPSG = "epsg:4522";
        } else if (longitude >= 103.3 && longitude < 106.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 35
            degree3EPSG = "epsg:4523";
        } else if (longitude >= 106.3 && longitude < 109.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 36
            degree3EPSG = "epsg:4524";
        } else if (longitude >= 109.3 && longitude < 112.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 37
            degree3EPSG = "epsg:4525";
        } else if (longitude >= 112.3 && longitude < 115.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 38
            degree3EPSG = "epsg:4526";
        } else if (longitude >= 115.3 && longitude < 118.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 39
            degree3EPSG = "epsg:4527";
        } else if (longitude >= 118.3 && longitude < 121.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 40
            degree3EPSG = "epsg:4528";
        } else if (longitude >= 121.3 && longitude < 124.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 41
            degree3EPSG = "epsg:4529";
        } else if (longitude >= 124.3 && longitude < 127.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 42
            degree3EPSG = "epsg:4530";
        } else if (longitude >= 127.3 && longitude < 130.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 43
            degree3EPSG = "epsg:4531";
        } else if (longitude >= 130.3 && longitude < 133.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 44
            degree3EPSG = "epsg:4532";
        } else if (longitude >= 133.3) {
            // CGCS2000 / 3-degree Gauss-Kruger zone 45
            degree3EPSG = "epsg:4533";
        }
        CoordinateReferenceSystem CGCS2000 = crsFactory.createFromName(degree3EPSG);
        // 定义转换Factory
        CoordinateTransformFactory ctFactory = new CoordinateTransformFactory();
        CoordinateTransform wgs84ToCGCS2000 = ctFactory.createTransform(WGS84, CGCS2000);
        // 转换结果数据定义
        ProjCoordinate result = new ProjCoordinate();
        // 转换方法调用
        wgs84ToCGCS2000.transform(new ProjCoordinate(longitude, latitude), result);
        // 输出转换值: x前俩位表示的3度经度分带的中国区域内编号, x->longitude, y->latitude
        Map<String, Double> map = new HashMap();
        map.put("lon", result.x);
        map.put("lat", result.y);
        return map;
    }

    /**
     * 2000国家大地坐标系(CGCS2000)->WGS84
     * @param longitudeX CGCS2000经度值
     * @param latitudeY CGCS2000纬度值
     * @return x,y WGS84经度值,WGS84纬度值
     */
    public static String CGCS2000ToWGS84(double longitudeX, double latitudeY) {
        String degree3No = String.valueOf(BigDecimal.valueOf(longitudeX)).substring(0, 2);
        CRSFactory crsFactory = new CRSFactory();
        CoordinateReferenceSystem WGS84 = crsFactory.createFromName("epsg:4326");
        // 根据精度范围换算使用坐标标准
        String degree3EPSG = "epsg:4528";
        switch (degree3No) {
            case "25":
                degree3EPSG = "epsg:4513";
                break;
            case "26":
                degree3EPSG = "epsg:4514";
                break;
            case "27":
                degree3EPSG = "epsg:4515";
                break;
            case "28":
                degree3EPSG = "epsg:4516";
                break;
            case "29":
                degree3EPSG = "epsg:4517";
                break;
            case "30":
                degree3EPSG = "epsg:4518";
                break;
            case "31":
                degree3EPSG = "epsg:4519";
                break;
            case "32":
                degree3EPSG = "epsg:4520";
                break;
            case "33":
                degree3EPSG = "epsg:4521";
                break;
            case "34":
                degree3EPSG = "epsg:4522";
                break;
            case "35":
                degree3EPSG = "epsg:4523";
                break;
            case "36":
                degree3EPSG = "epsg:4524";
                break;
            case "37":
                degree3EPSG = "epsg:4525";
                break;
            case "38":
                degree3EPSG = "epsg:4526";
                break;
            case "39":
                degree3EPSG = "epsg:4527";
                break;
            case "40":
                degree3EPSG = "epsg:4528";
                break;
            case "41":
                degree3EPSG = "epsg:4529";
                break;
            case "42":
                degree3EPSG = "epsg:4530";
                break;
            case "43":
                degree3EPSG = "epsg:4531";
                break;
            case "44":
                degree3EPSG = "epsg:4532";
                break;
            case "45":
                degree3EPSG = "epsg:4533";
                break;
        }
        CoordinateReferenceSystem CGCS2000 = crsFactory.createFromName(degree3EPSG);
        CoordinateTransformFactory ctFactory = new CoordinateTransformFactory();
        // 转换区别实际就这一行创建转换器的代码,前后顺序变了
        CoordinateTransform cgcs2000ToWGS84 = ctFactory.createTransform(CGCS2000, WGS84);
        ProjCoordinate result = new ProjCoordinate();
        cgcs2000ToWGS84.transform(new ProjCoordinate(longitudeX, latitudeY), result);
        return BigDecimal.valueOf(result.x) + "," + BigDecimal.valueOf(result.y);
    }

    // 计算两个经纬度点之间的方位角
    public static double bearing(double lat1, double lon1, double lat2, double lon2) {
        // 将经纬度转换为弧度
        double lat1Rad = Math.toRadians(lat1);
        double lon1Rad = Math.toRadians(lon1);
        double lat2Rad = Math.toRadians(lat2);
        double lon2Rad = Math.toRadians(lon2);

        // 计算经度差
        double dLon = lon2Rad - lon1Rad;

        // 计算方位角
        double y = Math.sin(dLon) * Math.cos(lat2Rad);
        double x = Math.cos(lat1Rad) * Math.sin(lat2Rad) - Math.sin(lat1Rad) * Math.cos(lat2Rad) * Math.cos(dLon);
        double bearing = Math.atan2(y, x);

        // 将弧度转换为角度
        double bearingDegrees = Math.toDegrees(bearing);
        // 调整为正值
        return (bearingDegrees + 360) % 360;
    }

    // 根据起始点、方位角和距离计算移动后的经纬度坐标
    public static double[] destinationPoint(double lat1, double lon1, double bearing, double distance) {
        // 将经纬度转换为弧度
        double lat1Rad = Math.toRadians(lat1);
        double lon1Rad = Math.toRadians(lon1);
        double bearingRad = Math.toRadians(bearing);
        double angularDistance = distance / 6371.0; // 转换为弧度

        // 计算目标点的纬度
        double lat2Rad = Math.asin(Math.sin(lat1Rad) * Math.cos(angularDistance) +
                Math.cos(lat1Rad) * Math.sin(angularDistance) * Math.cos(bearingRad));

        // 计算目标点的经度
        double lon2Rad = lon1Rad + Math.atan2(Math.sin(bearingRad) * Math.sin(angularDistance) * Math.cos(lat1Rad),
                Math.cos(angularDistance) - Math.sin(lat1Rad) * Math.sin(lat2Rad));

        // 将计算结果转换为角度
        double lat2 = Math.toDegrees(lat2Rad);
        double lon2 = Math.toDegrees(lon2Rad);

        return new double[]{lon2, lat2};
    }

}
